In [68]:
import os
import re
import sys
import StringIO
from qumulo.lib.request import RequestError
from qumulo.rest_client import RestClient
In [69]:
# set your environment variables or fill in the variables below
API_HOSTNAME = os.environ['API_HOSTNAME'] if 'API_HOSTNAME' in os.environ else '{your-cluster-hostname}'
API_USER = os.environ['API_USER'] if 'API_USER' in os.environ else '{api-cluster-user}'
API_PASSWORD = os.environ['API_PASSWORD'] if 'API_PASSWORD' in os.environ else '{api-cluster-password}'
In [70]:
rc = RestClient(API_HOSTNAME, 8000)
rc.login(API_USER, API_PASSWORD)
print("logged in as: %(name)s" % rc.auth.who_am_i())
arguments:
*Either dir_path or dir_id is required
arguments:
arguments:
arguments:
In [71]:
base_path = '/'
dir_name = 'test-qumulo-fs-data'
try:
the_dir_meta = rc.fs.create_directory(dir_path=base_path, name=dir_name)
print("Successfully created %s%s." % (base_path, dir_name))
except RequestError as e:
print("** Exception: %s - Details: %s\n" % (e.error_class,e))
if e.error_class == 'fs_entry_exists_error':
the_dir_meta = rc.fs.get_attr(base_path + dir_name)
for k, v in the_dir_meta.iteritems():
if re.search('(id|size|path|change_time)', k):
print("%19s - %s" % (k, v))
In [73]:
file_name = 'first-file.txt'
# relies on the base path and direcotry name created in the code above.
try:
the_file_meta = rc.fs.create_file(name=file_name, dir_path=base_path + dir_name)
except RequestError as e:
print("** Exception: %s - Details: %s\n" % (e.error_class,e))
if e.error_class == 'fs_entry_exists_error':
the_file_meta = rc.fs.get_attr(base_path + dir_name + '/' + file_name)
print("We've got a file. Its id is: %s" % the_file_meta['id'])
In [74]:
# writing a local file from /tmp/ to the qumulo cluster
fw = open("/tmp/local-file-from-temp.txt", "w")
fw.write("Let's write 100 sentences on this virtual chalkboard\n" * 100)
fw.close()
write_file_meta = rc.fs.write_file(data_file=open("/tmp/local-file-from-temp.txt"),
path=base_path + dir_name + '/' + file_name)
print("""name: %(path)s
bytes: %(size)s
mod time: %(modification_time)s""" % write_file_meta)
In [75]:
string_io_file_name = 'write-from-string-io.txt'
try:
rc.fs.create_file(name=string_io_file_name, dir_path=base_path + dir_name)
except RequestError as e:
print("Exception: %s - Details: %s\n" % (e.error_class,e))
fw = StringIO.StringIO()
fw.write("Let's write 200 sentences on this virtual chalkboard\n" * 200)
write_file_meta = rc.fs.write_file(data_file=fw,
path=base_path + dir_name + '/' + string_io_file_name)
fw.close()
print("""name: %(path)s
bytes: %(size)s
mod time: %(modification_time)s""" % write_file_meta)
In [ ]: